package com.ailk.cuc.autotestbg.common.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;

public class PropUtils {
	
	private static Log logger = LogUtils.getLogger(PropUtils.class.getName());
	private static Properties properties;
	
	public static void init(String file){
		if(properties == null){
			try {
				InputStream input = PropUtils.class.getClassLoader().getResourceAsStream(file);
				properties = new Properties();
				properties.load(input);
				logger.debug("属性文件："+file+" 加载成功");
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				logger.error("文件不存在 :　"+file);
				logger.error(e.getMessage());
			} catch (IOException e) {
				e.printStackTrace();
				logger.error("读取文件　"+file+" 发生异常");
				logger.error(e.getMessage());
			}
		}
	}
	
	public static String getValueByName(String key){
		logger.debug("获取属性 ："+key);
		return properties.getProperty(key);
	}
	
}
